package com.zygh.policeasset.controller;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.zygh.policeasset.component.CommonResult;
import com.zygh.policeasset.pojo.AssetsStepsProcess;
import com.zygh.policeasset.pojo.FileModification;
import com.zygh.policeasset.service.AssetsStepsProcessService;
import com.zygh.policeasset.service.CompletedSerivce;
import com.zygh.policeasset.service.ContractService;
import com.zygh.policeasset.service.FileModificationService;
import com.zygh.policeasset.service.FinalStatementService;
import com.zygh.policeasset.service.ProjectService;
import com.zygh.policeasset.service.SettlementService;
import com.zygh.policeasset.service.TenderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping({"/filemodification"})
@Api(tags = {"档案修改申请"})
@RestController
/* loaded from: police-asset-2.0-0.0.1-SNAPSHOT.jar:BOOT-INF/classes/com/zygh/policeasset/controller/FileModificationController.class */
public class FileModificationController {
    @Autowired
    FileModificationService fileModificationService;
    @Autowired
    ProjectService projectService;
    @Autowired
    TenderService tenderService;
    @Autowired
    ContractService contractService;
    @Autowired
    CompletedSerivce completedSerivce;
    @Autowired
    SettlementService settlementService;
    @Autowired
    FinalStatementService finalStatementService;
    @Autowired
    AssetsStepsProcessService assetsStepsProcessService;

    @RequestMapping(value = {"/findAllProjectType"}, method = {RequestMethod.GET})
    @ApiOperation("获取档案修改项目名称列表")
    public Object findAllProjectType(@RequestParam("type") String type) {
        if (type.equals("lx")) {
            return new CommonResult().success(this.projectService.selectBytype());
        }
        if (type.equals("zb")) {
            return new CommonResult().success(this.tenderService.selectBytype());
        }
        if (type.equals("ht")) {
            return new CommonResult().success(this.contractService.selectBytype());
        }
        if (type.equals("jgys")) {
            return new CommonResult().success(this.completedSerivce.selectBytype());
        }
        if (type.equals("sjjs")) {
            return new CommonResult().success(this.settlementService.selectBytype());
        }
        if (type.equals("sjjues")) {
            return new CommonResult().success(this.finalStatementService.selectBytype());
        }
        return new CommonResult().validateFailed("参数有误");
    }

    @RequestMapping(value = {"/findSectionByType"}, method = {RequestMethod.GET})
    @ApiOperation("获取标段名称列表")
    public Object findSectionByType(@RequestParam("type") String type, @RequestParam("projectNo") String projectNo) {
        if (type.equals("ht")) {
            return new CommonResult().success(this.contractService.findSectionByType(projectNo));
        }
        if (type.equals("jgys")) {
            return new CommonResult().success(this.completedSerivce.findSectionByType(projectNo));
        }
        if (type.equals("sjjs")) {
            return new CommonResult().success(this.settlementService.findSectionByType(projectNo));
        }
        if (type.equals("sjjues")) {
            return new CommonResult().success(this.finalStatementService.findSectionByType(projectNo));
        }
        return new CommonResult().validateFailed("参数有误");
    }

    @RequestMapping(value = {"/"}, method = {RequestMethod.GET})
    @ApiOperation("获取档案修改申请分页列表")
    public Object findAll(@RequestParam(defaultValue = "1", value = "pageNum") int pageNum, @RequestParam(defaultValue = "10", value = "pageSize") int pageSize, @RequestParam("status") Integer status) {
        return this.fileModificationService.queryAll(pageNum, pageSize, status);
    }

    @RequestMapping(value = {"/add"}, method = {RequestMethod.POST})
    @ApiOperation("添加")
    public Object add(@RequestBody FileModification fileModification) {
        if (this.fileModificationService.add(fileModification) > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("添加错误");
    }

    @RequestMapping(value = {"/remove"}, method = {RequestMethod.GET})
    @ApiImplicitParam(name = "id", value = "唯一主键", required = true, paramType = "query")
    @ApiOperation("删除")
    public Object delete(Integer id) {
        if (StrUtil.isEmpty(String.valueOf(id))) {
            return new CommonResult().validateFailed("id不能为空");
        }
        if (this.fileModificationService.deleteById(id) > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("删除失败");
    }

    @RequestMapping(value = {"/selectbyid"}, method = {RequestMethod.GET})
    @ApiImplicitParam(name = "id", value = "唯一主键", required = true, paramType = "query")
    @ApiOperation("通过ID查询")
    public Object selectById(Integer id) {
        if (StrUtil.isEmpty(String.valueOf(id))) {
            return new CommonResult().validateFailed("id不能为空");
        }
        return new CommonResult().success(this.fileModificationService.queryById(id));
    }

    @RequestMapping(value = {"/update"}, method = {RequestMethod.POST})
    @ApiOperation("更新")
    public Object update(@RequestBody FileModification fileModification) {
        if (this.fileModificationService.update(fileModification) > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("更新失败");
    }

    @RequestMapping(value = {"/updatebyid"}, method = {RequestMethod.GET})
    @Transactional
    @ApiOperation("修改状态")
    public Object updateByid(@RequestParam("id") Integer id, @RequestParam("status") Integer status, @RequestParam("userId") Integer userId, @RequestParam("opinion") String opinion, @RequestParam("type") String type) {
        int count = this.fileModificationService.updateByid(id, status);
        AssetsStepsProcess assetsStepsProcess = new AssetsStepsProcess();
        assetsStepsProcess.setAssetsStepsId(id);
        assetsStepsProcess.setDoTime(DateUtil.now());
        assetsStepsProcess.setUserId(userId);
        assetsStepsProcess.setOpinion(opinion);
        assetsStepsProcess.setStatus(status);
        assetsStepsProcess.setType(type);
        this.assetsStepsProcessService.add(assetsStepsProcess);
        if (count > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("更新失败");
    }

    @RequestMapping(value = {"/updatedealWithByid"}, method = {RequestMethod.GET})
    @ApiOperation("修改是否处理状态")
    public Object updatedealWithByid(@RequestParam("id") Integer id, @RequestParam("dealWith") Integer dealWith) {
        if (this.fileModificationService.updatedealWithByid(id, dealWith) > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("更新失败");
    }
}